<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'addexam.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script type="text/javascript">
			function change(){
				var flag = document.getElementById("flag");
				var trs = document.getElementsByTagName("TR");
				var tab = document.getElementById("tab");
				var answer = document.getElementById("answer");
				var ans = document.getElementById("ans");
				var answerA = document.getElementById("answerA");
				var answerB = document.getElementById("answerB");
				var answerC=document.createElement("option");
				answerC.setAttribute("value","C");
				answerC.innerHTML="C";
				var answerD=document.createElement("option");
				answerD.setAttribute("value","D");
				answerD.innerHTML="D";
				if (flag.value == 1) {
					for ( var i = 2; i < 6; i++) {
						trs.item(i).style.display = "table-row";
	
					}
					answer.innerHTML = "正确选项";
					answerA.innerHTML = "A";
					answerA.value = "A";
					answerB.innerHTML = "B";
					answerB.value = "B";
					ans.appendChild(answerC);
					ans.appendChild(answerD);
					
				} else {
					for ( var i = 2; i < 6; i++) {
						trs.item(i).style.display = "none";
					}
					answer.innerHTML = "正确答案";
					answerA.innerHTML = "对";
					answerA.value = "对";
					answerB.innerHTML = "错";
					answerB.value = "错";
					ans.remove(2);
					ans.remove(2);
				}
			}
		</script>
	</head>

	<body onload="change();">
		<s:form action="exam!addExam.action" namespace="/">
			<table id="tab">
				<tr>
					<td>
						题 型
					</td>
					<td>
						<select name="flag" id="flag" onchange="change();">
							<option value="1">
								选择题
							</option>
							<option value="0">
								判断题
							</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						题 干
					</td>
					<td>
						<input type="text" name="question" size="100" />
					</td>
				</tr>
				<tr>
					<td>
						选项A
					</td>
					<td>
						<input type="text" name="optionA" size="35" />
					</td>
				</tr>
				<tr>
					<td>
						选项B
					</td>
					<td>
						<input type="text" name="optionB" size="35" />
					</td>
				</tr>
				<tr>
					<td>
						选项C
					</td>
					<td>
						<input type="text" name="optionC" size="35" />
					</td>
				</tr>
				<tr>
					<td>
						选项D
					</td>
					<td>
						<input type="text" name="optionD" size="35" />
					</td>
				</tr>
				<tr>
					<td id="answer">
						正确选项
					</td>
					<td>
						<select name="answer" id="ans">
							<option value="A" id="answerA">
								A
							</option>
							<option value="B" id="answerB">
								B
							</option>
						</select>
					</td>
				</tr>

				<tr>
					<td></td>
					<td>
						<input type="submit" value="提交" />
					</td>
				</tr>
			</table>
		</s:form>
	</body>
</html>
